<?php defined('DML') or die("Access locked");

include PATH.DS.'includes'.DS.'snippets'.DS.'inclScript.php';

$conf = new Config;

define('CSS', BASEHREF.'tamplates/'.$conf->tamplate.'/');
define("META", $scripts);

$tpl['main'] = PATH.DS.'tamplates'.DS.$conf->tamplate.DS.'index.tpl';
$tpl['form'] = PATH.DS.'tamplates'.DS.$conf->tamplate.DS.'addnote.tpl';
$tpl['archiv'] = PATH.DS.'tamplates'.DS.$conf->tamplate.DS.'archiv.tpl';

$data['title'] = "Новая заметка - ".$conf->title;

$mysql = new MySQL($conf->dbhost, $conf->dbuser, $conf->dbpassw, $conf->db, $tpl);
if(isset($_REQUEST['DoGo'])){
   $author = $_SESSION['userid'];
   $bln = FALSE;
   if($_POST['note'] !== "<br>"){
      $bln = TRUE;
      $note = $_POST['note'];
   }
   if($bln == TRUE){
      $result = $mysql->AddNote($author, $note);
   }else{
      $data['message'] = "<font style=\"color:red\">Поле с заметкой не должно быть пустым.</font><br />";
   }
   
   if($result){
      $data['message'] = "<font style=\"color:red\">Новая заметка была успешно добавленна.</font><br /><br />";
   }else{
      $data['message'] .= "<font style=\"color:red\">Заметк не добавленна!!!</font><br /><br />";
   }
   
   $data['content'] = ParseTamplatePath($data, $tpl['form']);
}else{
   $data['content'] = ParseTamplatePath($data, $tpl['form']);
}
$mysql->ArchiveNotes();
$data['archiv'] = $mysql->ParseTemplate('archiv');

$html = ParseTamplatePath($data, $tpl['main']);
echo $html;
echo "Запросов к базе ".$mysql->total_queries."<br />";
?>
